/**
 * 
 */
package org.springside.examples.miniweb.entity.report;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import org.springframework.format.annotation.DateTimeFormat;

/**
 * @author Eric 2012-3-11
 * 
 * @since 6.0
 * 
 */
@MappedSuperclass
public abstract class AssignedReport extends ReportIdEntity implements Comparable<AssignedReport>, Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1011486515734135758L;

	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date scheduleFinish;
	
	@DateTimeFormat(pattern="yyyy-MM-dd")
	private Date updateTime;
	
	private String customerName;
	
	/**
	 * @return the end
	 */
	@Transient
	public String getEnd() {
		if (status.equalsIgnoreCase("finish")) {
			if (!this.updateTime.after(this.getScheduleFinish())) {
				return "intime";
			} else {
				return "";
			}
		}
		return "";
	}


	@Column(nullable = false)
	public String getCustomerName() {
		return customerName;
	}
	

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}
	
	/**
	 * @return the updatetime
	 */
	public Date getUpdateTime() {
		return updateTime;
	}


	/**
	 * @param updatetime the updatetime to set
	 */
	public void setUpdateTime(Date updatetime) {
		this.updateTime = updatetime;
	}

	
	private String assignedUser;
	
	/**
	 * @param assignedUser
	 *            the assignedUser to set
	 */
	public void setAssignedUser(String assignedUser) {
		this.assignedUser = assignedUser;
	}
	
	/**
	 * @return the assignedUser
	 */
	public String getAssignedUser() {
		return assignedUser;
	}
	
	/**
	 * @return the scheduleFinish
	 */
	public Date getScheduleFinish() {
		return scheduleFinish;
	}
	
	/**
	 * @param scheduleFinish
	 *            the scheduleFinish to set
	 */
	public void setScheduleFinish(Date scheduleFinish) {
		this.scheduleFinish = scheduleFinish;
	}


	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	@Transient
	public int compareTo(AssignedReport o) {
		int result1 = this.getAssignedUser().compareTo(o.getAssignedUser());
		int result2 = 0;
		if(result1 == 0){
			result2 = this.getStatus().compareTo(o.getStatus());
			if(result2 == 0){
				return this.getScheduleFinish().compareTo(o.getScheduleFinish());
			}
			return result2;
		}
		return result1;
	}
}
